import store from "@/store";
export default {
  get: (key, val) => {
    return store.state.app.filters[key]
      ? store.state.app.filters[key][val]
      : "";
  },
  list: (key, type) => {
    if (!store.state.app.filters[key]) return [];
    return Object.keys(store.state.app.filters[key]).map((k) => {
      const val = !isNaN(parseFloat(k)) && isFinite(k) ? k * 1 : k;
      return {
        label: store.state.app.filters[key][k],
        value: type === "String" ? String(val) : val,
      };
    });
  },
  validatePhone(_rule, value) {
    if (value === "") {
      return Promise.reject("请输入手机号码！");
    } else if (!/^1\d{10}$/.test(value)) {
      return Promise.reject("请输入正确的手机号码！");
    } else {
      return Promise.resolve();
    }
  },
  validateEmail(_rule, value) {
    var emailReg =
      /^([a-zA-Z0-9]+[_|_|.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|_|.]?)*[a-zA-Z0-9]+.[a-zA-Z]{2,3}$/;
    if (value === "") {
      return Promise.reject("请输入邮箱地址！");
    } else if (!emailReg.test(value)) {
      return Promise.reject("请输入正确的邮箱地址！");
    } else {
      return Promise.resolve();
    }
  },
};
